import request from '../request'

const Api = {
  onlinePaging: '/api/sys/exam/online-paging',
  fetchDetail: '/api/sys/exam/detail',
  examPaging: '/api/sys/exam/paging',
  examSave: '/api/sys/exam/save',
  examDelete: '/api/sys/exam/delete',

  paperDetail: '/api/sys/paper/paper-detail',
  quDetail: '/api/sys/paper/qu-detail',
  createPaper: '/api/sys/paper/create-paper',
  fillAnswer: '/api/sys/paper/fill-answer',
  handExam: '/api/sys/paper/hand-exam',
  paging: '/api/sys/paper/paging',
  paperResult: '/api/sys/paper/paper-result',

  myPaging: '/api/sys/userExam/my-paging',
  usersPaging: '/api/sys/userExam/paging',

  bookPaging: '/api/sys/wrong-book/paging',


  quQuDetail: '/api/sys/qu/detail',
  quPaging: '/api/sys/qu/paging',
  saveData: '/api/sys/qu/save',
  removeBatch: '/api/sys/qu/delete',
  exportExcel: '/api/sys/qu/export',
}


export const onlinePaging = data => {
    return request.request({
        url: Api.onlinePaging,
        params: data,
        method: 'GET'
    })
}
/**试卷详情**/
export const quDetail = data => {
  return request.request({
    url: Api.quDetail,
    data: data,
    method: 'POST'
  })
}
/**题库详情**/
export const fetchDetail = data => {
  return request.request({
    url: Api.fetchDetail,
    data: data,
    method: 'POST'
  })
}
/**题目详情**/
export const paperDetail = data => {
    return request.request({
        url: Api.paperDetail,
        data: data,
        method: 'POST'
    })
}
/**创建试卷**/
export const createPaper = data => {
  return request.request({
    url: Api.createPaper,
    data: data,
    method: 'POST'
  })
}

/**填充答案**/
export const fillAnswer = data => {
  return request.request({
    url: Api.fillAnswer,
    data: data,
    method: 'POST'
  })
}

/**交卷**/
export const handExam = data => {
  return request.request({
    url: Api.handExam,
    data: data,
    method: 'POST'
  })
}

/**我的成绩分页列表**/
export const myPaging = data => {
  return request.request({
    url: Api.myPaging,
    params: data,
    method: 'GET'
  })
}
/**我的成绩-详情**/
export const paging = data => {
  return request.request({
    url: Api.paging,
    data: data,
    method: 'POST'
  })
}

/**错题本分页列表**/
export const bookPaging = data => {
  return request.request({
    url: Api.bookPaging,
    data: data,
    method: 'POST'
  })
}
export const usersPaging = data => {
  return request.request({
    url: Api.usersPaging,
    data: data,
    method: 'POST'
  })
}

/**错题本分页列表**/
export const quQuDetail = data => {
  return request.request({
    url: Api.quQuDetail,
    data: data,
    method: 'POST'
  })
}

/**试卷结果详情**/
export const paperResult = data => {
  return request.request({
    url: Api.paperResult,
    data: data,
    method: 'POST'
  })
}
export const saveData = data => {
  return request.request({
    url: Api.saveData,
    data: data,
    method: 'POST'
  })
}
/** 批量删除 */
export const removeBatch = data => {
  return request.request({
    url: Api.removeBatch,
    data: data,
    method: 'DELETE'
  })
}
export const examDelete = data => {
  return request.request({
    url: Api.examDelete,
    data: data,
    method: 'DELETE'
  })
}
/** 导出 */
export const exportExcel = data => {
  request.request({
    url: Api.exportExcel,
    data: data,
    method: 'POST',
    responseType: 'blob',
  }).then((result) => {

    if (!result) return;
    let url = window.URL.createObjectURL(new Blob([result]));
    let link = document.createElement('a');
    link.style.display = 'none';
    link.href = url;
    link.setAttribute('download', '导出的数据.xlsx');
    document.body.appendChild(link);
    link.click()
    document.body.removeChild(link);
  })
}
/**试题分页列表*/
export const quPaging = data => {
  return request.request({
    url: Api.quPaging,
    data: data,
    method: 'POST'
  })
}
/**试卷分页列表*/
export const examPaging = data => {
    return request.request({
      url: Api.examPaging,
      data: data,
      method: 'POST'
    })
  }
export const examSave = data => {
    return request.request({
      url: Api.examSave,
      data: data,
      method: 'POST'
    })
  }
